package com.qfedu.zy.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class ZanHandler {

    @Autowired
    private StringRedisTemplate redisTemplate;

    public void addZan(String itemId,int userId){
        String key =  "redis-zan-"+itemId+"-"+userId;
        redisTemplate.boundValueOps(key).set("1");
    }

    public void countZan(String itemId){
        String key = "redis-zan-"+itemId;

        String count = redisTemplate.boundValueOps(key).get();

        if(count == null || "".equals(count)){
            redisTemplate.boundValueOps(key).set("1");
        }else {
            int i = Integer.parseInt(count)+1;
            redisTemplate.boundValueOps(key).set(i+"");
        }
    }

}
